Graphical and Latent Variable Modeling


Michael Clark
Statistician Lead

Starting Out

Document

m-clark.github.io/docs/sem

Data Etc.

m-clark.github.io/docs/sem/sem_workshop.zip

Steps:

  • Download
  • Unzip
  • Open RStudio
  • File/Open Project…
  • Click on SEM.Rproj
  • File/Open/readMe.md

Exercises

For exercises, open the exercises_nb.nb.html

with your browser!

Or go to:

m-clark.github.io/docs/sem/exercises/exercises_nb.nb.html

Outline

Preliminaries

Graphical Modeling

Latent Variables

SEM

Overview of others

Goal

Give a broad overview of techniques related to SEM

Note connection to others

Be clear on limitations

Primary components

Scripts/Docs

Console

Viewer

Other





Scripts/Docs

For this workshop, use traditional R script or notebook

Script is where your code goes

Ctrl+Enter will run current line or selected lines

Console

Where the code is run

Typically your output will be viewed here

Avoid using directly

Viewer

Visualizations

Other HTML

Other

RStudio tries to make things easier

  • Keyboard shortcuts
  • Auto-complete

Let it!

Intro2R

Basics

Objects, Functions

Classes

Installing packages

Code

Using functions to create output

Print the object to view it

myobj = function(arg1=input1, argA=inputA)  
myobj

Code

  • The following creates the object nums

  • sum sums the elements of nums

  • The result is assigned to the object numsSum

  • Object is printed to view it

nums = c(1,2,3,4)      # c is a function that combines its elements
class(nums)
[1] "numeric"
numsSum = sum(nums)     
numsSum
[1] 10

Example lavaan code

library(lavaan)                     # loads the library

myModel = "
 # latent variables aka measurment models
 Factor1 =~ x1 + x2 + x3            
 Factor2 =~ y1 + y2 + y3

 # regresssions aka structural model
 Factor2 ~ Factor1 + z1 + z3
"

mySEM = sem(myModel, otherinputs)   # run the model
summary(mySem)                      # display results

Save your work

Always save your scripts

If desired, can save your work as RData file

save(obj1, obj2, file='filelocation/myRstuff.RData')

save.image('filelocation/myRstuff.RData')     # saves everything

Graphical Models

Overview

Directed Graphs

  • Path Analysis

  • Mediation

  • Bayesian Networks

Undirected

  • Network analysis

Graphical Models

Nodes, vertices

May define variables, observations, concepts

Edges, links

Define connections, relations

Directed, Undirected, Mixed

Path analysis

Extends regression to:

  • Multiple targets

  • Indirect effects

Multiple targets

Does not require SEM

Common in some areas:

  • traditional ‘multivariate’ models
  • zero-inflated models
  • one-deck encoding

Indirect effects

\(A \rightarrow B \rightarrow C\)

Indirect effects

Still may include direct path

Always more complicated than three variables

Issues in mediation

Very difficult to justify in cross-sectional setting

Strong causal implications

Does not prove a causal relationship

Other techniques

Bayesian Networks

Network Analysis

Latent Variables

Uses of latent variables

Data Compression

Measurement of Latent Constructs

Other

Data compression

Take many things and produce few

Might focus on variance (e.g. PCA) or covariance (FA)

Use estimated scores in other analysis

Measurement of Constructs

Underlying causal model

\[ x = \lambda \textrm{F} + \epsilon \]

\[ \epsilon = \textrm{systematic + measurement error} \]

Examples

Psychological constructs

Scholastic abilities

Topics in text

Issues

Number of factors

Loadings, interpretation

Scale development, reliability

Structural Equation Modeling

SEM

Putting it all together

Measurement model
+
Structural model

Putting it all together

Factor Analysis
+
Regression

Issues

Many, including:

  • How to assess fit

  • Identification

  • Estimation techniques

  • Model complexity

  • Sample Size

How to fool yourself

  • Too little data

  • ‘Poor’ data

  • Ignoring performance, diagnostics

Other SEM

Latent Classes

Growth Curves

Multi-sample

Reasons NOT to do SEM

Because it sounds cool

Reasons NOT to do SEM

Because you see it in a paper

Reasons NOT to do SEM

Because you can’t get a large sample

Reasons to DO SEM

It’s can answer your specific research question better than alternatives

Reasons to DO SEM

Very strong result if it works

Reasons to DO SEM

Measurement is of focus

Reasons to DO SEM

Ties to causal thinking

Reasons to DO SEM

Flexibility with Complexity

Good luck!